import re
def insert_keyword(s, old_key, new_key , is_after = False): 
    try:
        index = s.index(old_key) + int(is_after) * len(old_key)
        return s[:index] + new_key + s[index:]
    except ValueError:
        return s
    
def format_think_content(text):
    """
    将 <think> 内容包裹在带有样式的 <span> 中
    """
    # 定义 <think> 内容的样式
    think_style = (
        'style="display: block; font-size: 16px; color: gray; '
        'font-family: 宋体; font-style: italic; background-color: #f0f0f0; padding: 10px;"'
    )

    # 使用正则表达式提取 <think> 内容
    think_pattern = re.compile(r"<think>(.*?)</think>", re.DOTALL)
    formatted_text = think_pattern.sub(
        lambda match: f'<span {think_style}>{match.group(1)}</span>',
        text
    )

    return formatted_text